$(function () {
    $.when(getdatadictionary("cross_type")).done($("#jqGrid").jqGrid({
        url: baseURL + 'api/bcrossquantities/list?aguid=' + GetUrlParam("aguid"),
        datatype: "json",
        colModel: [
            {label: 'guid', name: 'guid', index: 'guid', width: 50, key: true, hidden: true},
            {label: '所属预算标准ID', name: 'bGuid', index: 'b_guid', width: 80, hidden: true},
            {
                label: '交叉跨越类型', name: 'cQType', index: 'c_q_type', width: 80,
                formatter: function (cellvalue, options, rowObject) {
                    for (d in cross_type) {
                        if (cellvalue == cross_type[d].dKey) return cross_type[d].dValue;
                    }
                }
            },
            {label: '计量单位', name: 'cQUnit', index: 'c_q_unit', width: 80},
            {label: '导线横截面积(mm2)下限', name: 'cQAreaLower', index: 'c_q_area_lower', width: 80},
            {label: '导线横截面积(mm2)上限', name: 'cQAreaHigh', index: 'c_q_area_high', width: 80},
            {label: '宽度(m)下限', name: 'cQWideLower', index: 'c_q_wide_lower', width: 80},
            {label: '宽度(m)上限', name: 'cQWideHigh', index: 'c_q_wide_high', width: 80},
            {label: '单价(元)', name: 'cQPrice', index: 'c_q_price', width: 80}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    }));
});
var cross_type;
function getdatadictionary(sss) {

    $.get(baseURL + "api/bdatadictionary/select?d_code=" + sss, function (r) {
        if (sss == "cross_type") {
            cross_type = r.returnlist;
        }
    });
}
var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        bCrossQuantities: {},
        cross_type: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.bCrossQuantities = {};
            vm.cross_type = cross_type;
            vm.bCrossQuantities.bGuid=GetUrlParam("aguid");
        },
        update: function (event) {
            var guid = getSelectedRow();
            if (guid == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";
            vm.cross_type = cross_type;
            vm.getInfo(guid)
        },
        saveOrUpdate: function (event) {
            var url = vm.bCrossQuantities.guid == null ? "api/bcrossquantities/save" : "api/bcrossquantities/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.bCrossQuantities),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (event) {
            var guids = getSelectedRows();
            if (guids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "api/bcrossquantities/delete",
                    contentType: "application/json",
                    data: JSON.stringify(guids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getInfo: function (guid) {
            $.get(baseURL + "api/bcrossquantities/info/" + guid, function (r) {
                vm.bCrossQuantities = r.bCrossQuantities;
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page
            }).trigger("reloadGrid");
        }
    }
});